package com.qianchang.microfinance.view.credit.data;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.dm.library.utils.FormatUtil;
import com.dm.library.utils.ViewUtils;
import com.dm.library.widgets.element.DTextView;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.LoanProductBean;
import com.qianchang.microfinance.bean.RechargeProjectBean;
import com.qianchang.microfinance.bean.SubmitLoanBean;
import com.qianchang.microfinance.global.ConstantAppInfo;
import com.qianchang.microfinance.view.base.BaseRecyclerAdapter;
import com.qianchang.microfinance.view.mine.loan.ConfirmAgreementActivity;

import butterknife.BindView;
import butterknife.ButterKnife;


public class RecharListAdapter extends BaseRecyclerAdapter<RechargeProjectBean> implements View.OnClickListener {

    private static final String TAG = "RecharListAdapter";


    public RecharListAdapter(Context context) {
        super(context, BaseRecyclerAdapter.ONLY_FOOTER);
    }


    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_recharge_project, parent, false);
        return new MyLoanViewHolder(view);
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, RechargeProjectBean item, int position) {
        MyLoanViewHolder myLoanViewHolder = (MyLoanViewHolder) holder;

        myLoanViewHolder.tvPeriod.setTextContent(item.getDeadline());
        String createTime = item.getCreateDate();
        myLoanViewHolder.tvApplyDate.setTextContent(ViewUtils.formatDateToDay(createTime));
        String status = item.getIsMoneyAuth();
        double loanAmount = item.getApplyAmount();

        if (loanAmount == 0) {
            myLoanViewHolder.tvMoney.setTextContent(FormatUtil.numKbPointFormat(item.getApplyAmount()));
        } else {
            myLoanViewHolder.tvMoney.setTextContent(FormatUtil.numKbPointFormat(loanAmount));
        }
        if ("0".equals(status)) {
            myLoanViewHolder.tvStatus.setTextContent("未认证");
        } else if ("1".equals(status)) {
            myLoanViewHolder.tvStatus.setTextContent("已认证");
        } else if ("2".equals(status)) {
            myLoanViewHolder.tvStatus.setTextContent("认证失败");
        } else {
            myLoanViewHolder.tvStatus.setTextContent("未认证");
        }
        myLoanViewHolder.tvSureAgreement.setOnClickListener(this);
        myLoanViewHolder.tvSureAgreement.setTag(position);
    }

    @Override
    public void onClick(View v) {
    }


    static class MyLoanViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_money)
        DTextView tvMoney;
        @BindView(R.id.tv_period)
        DTextView tvPeriod;
        @BindView(R.id.tv_apply_title)
        DTextView tvApplyTitle;
        @BindView(R.id.tv_apply_date)
        DTextView tvApplyDate;
        @BindView(R.id.tv_status)
        DTextView tvStatus;
        @BindView(R.id.tv_sure_agreement)
        DTextView tvSureAgreement;
        @BindView(R.id.ll_status)
        LinearLayout llStatus;

        public MyLoanViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
